/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.dao;

import org.ipti.br.tag.entity.Configurations;
import org.ipti.br.tag.entity.Configurations_;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

/**
 *
 * @author israel
 */
@Stateless
public class ConfigurationsFacade extends AbstractFacade<Configurations> {

    @PersistenceContext(unitName = "TAG2PU")
    private EntityManager em;

    public ConfigurationsFacade() {
        super(Configurations.class);
    }

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public Configurations configurationsPerName(String name) {
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery<Configurations> cq = cb.createQuery(Configurations.class);
        Root<Configurations> from = cq.from(Configurations.class);
        Predicate predicate = cb.equal(from.get(Configurations_.name), name);
        cq.where(cb.and(predicate));

        return getEntityManager().createQuery(cq).getSingleResult();
    }
}
